<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
    <%= title %>
    <!-- <input  name="avatar" type="file" id="photo">

    <button id="upload">上传</button> -->
    <form id='editfile' method='post' action='/profile' enctype='multipart/form-data'>
      <input name="text" type="text"/>
      选择图片：<input name="upload_file" id='upfile' type='file'/>
      <input type='submit' value='提交'/>
  </form>
</body>
<script src="/javascripts/jquery-1.11.1.min.js"></script>
<script>
     /*上传文件*/
     $("#upload").click(function(){
            //do something
            var file = $("#photo")[0].files;
            //上次修改时间
            console.log("文件上次修改时间"+file[0].lastModifiedDate);
            //名称
            console.log("文件名称"+file[0].name);
            //大小 字节
            console.log("文件大小"+file[0].size);
            //类型
            console.log("文件类型"+file[0].type);
            //创建FormData对象
            var data = new FormData();
            //为FormData对象添加数据
            $.each(file, function(i, file) {
                data.append('upload_file', file);
            });
            console.log(data)
            $.ajax({
                data: data,
                url: '/profile',
                type:"post",
                dataType: 'JSON',
                contentType: false,    //不可缺
                processData: false,    //不可缺
                success: function(data){
                    console.log(data);
                    alert("上传成功！");
                },
                error: function(err){
                    console.log('error: ' + err);
                }
            });
        })
</script>
</html>